﻿using System.Data;
using Microsoft.ApplicationBlocks.Data;
using SmartMenu.Providers;
using visinia.SmartEngine.Providers;

namespace SmartMenu
{
    public class SqlDataProvider : SmartMenuDataProvider
    {
        #region INIT
        private static string _sqlConnectionString = null;

        public SqlDataProvider()
        {
            _sqlConnectionString = ProviderController.GetDataProviderConnectionString();
        }
        public string ConnectionString
        {
            get { return _sqlConnectionString; }
        }
        #endregion

        #region MENU
        public override IDataReader GetMenus()
        {
            return SqlHelper.ExecuteReader(ConnectionString, "MenuGetMenus");
        }
        public override IDataReader AddMenu(string Name)
        {
            return SqlHelper.ExecuteReader(ConnectionString, "MenuAddMenu", Name);
        }

        public override void UpdateMenu(int MenuId, string Name)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, "MenuUpdateMenu", MenuId, Name);
        }

        public override void DeleteMenu(int MenuId)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, "MenuDeleteMenu", MenuId);
        }

        public override IDataReader GetMenuItems()
        {
            return SqlHelper.ExecuteReader(ConnectionString, "MenuGetMenuItems");
        }
        public override IDataReader AddMenuItem(int MenuId, int ParentId, string Title, string Url, int Order, bool Visible, string Image)
        {
            return SqlHelper.ExecuteReader(ConnectionString, "MenuAddMenuItem", MenuId, ParentId, Title, Url, Order, Visible, Image);
        }

        public override void UpdateMenuItem(int MenuItemId, int MenuId, int ParentId, string Title, string Url, int Order, bool Visible, string Image)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, "MenuUpdateMenuItem", MenuItemId, MenuId, ParentId, Title, Url, Order, Visible, Image);
        }

        public override void DeleteMenuItem(int MenuItemId)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, "MenuDeleteMenuItem", MenuItemId);
        }
        #endregion
    }
}
